<?php
class IndexController extends Zend_Controller_Action {
	// Mảng tham số nhận được ở mỗi Action:
	protected $_arrParam;
	private $USER_ID = 0;
	private $URI = "/";
	private $URL_ACC_LOGIN = "/account/login/";
	private $DEFAULT_PROFILE_PICTURE = "default/img/no_image.jpg";
	private $ALERT_TYPE_ERROR = "alert-error";
	private $ALERT_TYPE_SUCCESS = "alert-success";
	public function init() {
		$this->_arrParam = $this->_request->getParams ();
		// Truyền ra view
		$this->view->arrParam = $this->_arrParam;
		
		// Xu li cho phan header
		$this->URI = $this->getRequest ()->getScheme () . "://" . $this->getRequest ()->getHttpHost () . $this->getRequest ()->getRequestUri ();
		$mAccount = new Default_Model_Account ();
		if (! $mAccount->hasIdentity ()) {
			$this->_redirect ( $this->URL_ACC_LOGIN . '?return_url=' . $this->URI );
		} else {
			// get user info
			$this->USER_ID = $mAccount->getUserId ();
			
			$this->view->fullname = $mAccount->getFullName ();
			$this->view->return_url = $this->URI;
			$this->view->userid = $mAccount->getUserId ();
			$strAvatar = $mAccount->getProfilePicture ();
			if ($strAvatar != "") {
				$this->view->my_avatar = $mAccount->getProfilePicture ();
			} else {
				$this->view->my_avatar = $this->DEFAULT_PROFILE_PICTURE;
			}
			// get report
			$mRep = new Default_Model_Report();
			$arrRep = $mRep->listAllReport();
			$this->view->arrRep = $arrRep;
		}
		// End xu li cho phan header
	}
	public function indexAction() {
		$mUser = new Default_Model_User();
		$mLoc = new Default_Model_Location();
		$mTour = new Default_Model_Tour();
		$mCmt = new Default_Model_Comment();
		$mPhoto = new Default_Model_Photo();
		$mReport = new Default_Model_Report();
		// count item
		$this->view->total_user = $mUser->countUser();
		$this->view->total_loc = $mLoc->countLocation();
		$this->view->total_tour = $mTour->countTour();
		$this->view->total_cmt = $mCmt->countComment();
		$this->view->total_photo = $mPhoto->countPhoto();
		$this->view->total_report = $mReport->countReport();
		
		// statistic
		$strYearStatistic = date("Y");
		$arrUserStatistic = null;
		$arrLocStatistic = null;
		$arrTourStatistic = null;
		for ($i=1; $i <= 12; $i++) {
			$strMonth = $i < 10 ? "0".$i : $i;
			$arrUserStatistic[] = count($mUser->userStatisticByMonth($strYearStatistic.'-'.$strMonth));
			$arrLocStatistic[] = count($mLoc->locationStatisticByMonth($strYearStatistic.'-'.$strMonth));
			$arrTourStatistic[] = count($mTour->tourStatisticByMonth($strYearStatistic.'-'.$strMonth));
		}
		$this->view->arrUserStatistic = $arrUserStatistic;
		$this->view->arrLocStatistic = $arrLocStatistic;
		$this->view->arrTourStatistic = $arrTourStatistic;
		
	}
}